package ph.com.gs3.formalistics.view.valueobjects.parsers;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import ph.com.gs3.formalistics.model.communicators.HttpCommunicatorModule;

public class DateUtilities {

	// @formatter:off
	public static final SimpleDateFormat SERVER_DATE_FORMAT = new SimpleDateFormat(HttpCommunicatorModule.SERVER_DATE_FORMAT, Locale.ENGLISH);
	
	public static final SimpleDateFormat DEFAULT_DISPLAY_DATE_ONLY_FORMAT = new SimpleDateFormat("MMM/dd/yyyy", Locale.ENGLISH);
	public static final SimpleDateFormat DEFAULT_DISPLAY_TIME_ONLY_FORMAT = new SimpleDateFormat("hh:mm:a", Locale.ENGLISH);
	public static final SimpleDateFormat DEFAULT_DISPLAY_DATE_TIME_FORMAT = new SimpleDateFormat("MMM/dd/yyyy hh:mm:a", Locale.ENGLISH);

	public static final SimpleDateFormat WIDGET_DISPLAY_DATE_ONLY_FORMAT = new SimpleDateFormat("MMM dd", Locale.ENGLISH);
	public static final SimpleDateFormat WIDGET_DISPLAY_TIME_ONLY_FORMAT = new SimpleDateFormat("hh:mm a", Locale.ENGLISH);
	
	public static final SimpleDateFormat LOG_DATE_ONLY_FORMAT = new SimpleDateFormat("yyyy_MM_dd", Locale.ENGLISH);
	// @formatter:on

	@SuppressWarnings("deprecation")
	public static boolean isDateToday(Date date) {

		Date today = new Date();

		if (date.getYear() != today.getYear()) {
			return false;
		}

		if (date.getMonth() != today.getMonth()) {
			return false;
		}

		if (date.getDate() != today.getDate()) {
			return false;
		}

		return true;
	}

	public static Date parseToServerDate(String rawDate) throws ParseException {

		return SERVER_DATE_FORMAT.parse(rawDate);

	}

	public static String getServerFormattedCurrentDate() {

		Date currentDate = new Date();
		return SERVER_DATE_FORMAT.format(currentDate);

	}

}
